Add port mappings to container list output#14438
Add port mappings to container list output#14438beena352 wants to merge 7 commits intomicrosoft:feature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds port mapping information to the container list output. When containers are created with -p/--publish, the mapped ports now appear in a new PORTS column in the table view and in JSON output.
Changes:
- Extended the IDL with
WSLAPortProtocolenum and addedPorts/PortsCountfields toWSLAContainerEntry, plusProtocoltoWSLAPortMapping - Added CLI-side port parsing from
--publishargs,FormatPorts()formatting, andPortInformation/PortOptionmodel structs - Populated port data in
ListContainerson the service side and added cleanup handling for the nested COM-allocated ports array
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslaservice/inc/wslaservice.idl | Added WSLAPortProtocol enum, Protocol to WSLAPortMapping, Ports/PortsCount to WSLAContainerEntry |
| src/windows/wslasession/WSLASession.cpp | Populate port data in ListContainers with error cleanup scope guard |
| src/windows/wslasession/WSLAContainer.h | Declared GetPorts() accessor |
| src/windows/wslasession/WSLAContainer.cpp | Implemented GetPorts() returning m_mappedPorts |
| src/windows/common/WSLAContainerLauncher.cpp | Set Protocol field in AddPort() |
| src/windows/WslcSDK/wslcsdk.cpp | Pass Protocol field through SDK |
| src/windows/wslc/services/ContainerModel.h | Added PortOption, PortInformation structs with JSON serialization |
| src/windows/wslc/services/ContainerService.h | Declared FormatPorts() |
| src/windows/wslc/services/ContainerService.cpp | Implemented FormatPorts(), extract ports in List(), pass ports in CreateInternal() |
| src/windows/wslc/tasks/ContainerTasks.cpp | Parse --publish args, add PORTS column to table output |
| test/windows/WSLATests.cpp | Added port mapping assertions to PortMappingsNat test and zero-port checks to existing tests |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR adds port mapping information to the container list output. When containers are created with -p, the PORTS column now displays mapped ports in the format host:port->container_port/protocol. The changes span the IDL, service, CLI, SDK, and test layers.
Changes:
- Extended
WSLAContainerEntryandWSLAPortMappingIDL structs withPorts/PortsCountandProtocolfields; addedWSLAPortProtocolenum. - Wired port data through the service (
ListContainers), CLI (FormatPorts,-pargument parsing viaAddPort), and SDK layers. - Added test verification that
ListContainersreturns correct port data for containers created with port mappings.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslaservice/inc/wslaservice.idl | Added WSLAPortProtocol enum, Protocol to WSLAPortMapping, and Ports/PortsCount to WSLAContainerEntry. |
| src/windows/wslasession/WSLASession.cpp | Populates port data in ListContainers with error-cleanup scope guard. |
| src/windows/wslasession/WSLAContainer.h | Declares GetPorts() accessor. |
| src/windows/wslasession/WSLAContainer.cpp | Implements GetPorts() returning m_mappedPorts. |
| src/windows/common/WSLAContainerLauncher.cpp | Sets Protocol = WSLAPortProtocolTCP in AddPort. |
| src/windows/WslcSDK/wslcsdk.cpp | Passes Protocol field when converting SDK port mappings to IDL. |
| src/windows/wslc/services/ContainerModel.h | Adds PortOption, PortInformation structs and Ports to ContainerOptions/ContainerInformation. |
| src/windows/wslc/services/ContainerService.h | Declares FormatPorts(). |
| src/windows/wslc/services/ContainerService.cpp | Implements FormatPorts(), extracts/frees port data in List(), wires ports through CreateInternal. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Parses -p/--publish, adds PORTS column to table output. |
| test/windows/WSLATests.cpp | Adds PortsCount assertions and new ListContainers port verification block in PortMappingsNat. |
You can also share your feedback on Copilot code review. Take the survey.
… into user/beenachauhan/container-port-mappings
There was a problem hiding this comment.
Pull request overview
Adds port mapping visibility end-to-end so wsl --container list can display published ports in a new PORTS column, backed by service-side ListContainers data.
Changes:
- Extends
WSLAContainerEntry(IDL) to includePorts/PortsCountand populates that data inWSLASession::ListContainers. - Propagates ports through the CLI model and adds formatting + a
PORTScolumn to table output. - Updates/extends WSLA tests to validate port mappings are returned by
ListContainers.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLATests.cpp | Adds assertions for PortsCount and validates port mapping data returned by ListContainers. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Adds PORTS column to container list table output. |
| src/windows/wslc/services/ContainerService.h | Declares FormatPorts() helper for CLI display. |
| src/windows/wslc/services/ContainerService.cpp | Implements FormatPorts() and extracts/frees port mappings returned from ListContainers. |
| src/windows/wslc/services/ContainerModel.h | Adds PortInformation to the CLI model and includes it in JSON serialization. |
| src/windows/wslasession/WSLASession.cpp | Allocates and returns port mapping arrays per container in ListContainers, with cleanup on error. |
| src/windows/wslasession/WSLAContainer.h | Exposes GetPorts() accessor on container implementation. |
| src/windows/wslasession/WSLAContainer.cpp | Implements GetPorts() accessor. |
| src/windows/service/inc/wslaservice.idl | Extends WSLAContainerEntry with Ports and PortsCount. |
Summary of the Pull Request
Add port mappings to container list output. When containers are created with
-p, the PORTS column incontainer listnow displays the mapped ports.PR Checklist
Detailed Description of the Pull Request / Additional comments
PortsandPortsCountfields toWSLAContainerEntryin the IDLWSLAPortProtocolenum (TCP/UDP) andProtocolfield toWSLAPortMappingin the IDLListContainerson the service sidePortInformationstruct andFormatPorts()on the CLI sidecontainer listtable output-p/--publishargument to pass ports during container creation viaAddPort()Validation Steps Performed
Ran
PortMappingsNattest — verifiedListContainersreturns correct HostPort, ContainerPort, and Family for both AF_INET and AF_INET6 mappings, across Bridged and Host network modes